#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cassert>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

using namespace std;
int main()
{
    int fds[2];
    int n = pipe(fds);
    assert(n == 0);

    pid_t id = fork();
    assert(id >= 0);
    if (id == 0)
    {
        // 子进程
        // 关闭写端
        close(fds[1]);
        char buffer[1024];

        read(fds[0], buffer, sizeof(buffer) - 1);
        buffer[strlen(buffer)] = 0;
        cout << buffer << endl;
        

        exit(0);
    }
    // 父进程
    //关闭读端
    close(fds[0]);
    const char *buffer = "i am father";
    write(fds[1],buffer,strlen(buffer));

    close(fds[0]);
    waitpid(id, nullptr, 0);

    return 0;
}